{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1. 查看显卡厂商\n",
    "\n",
    "```sh\n",
    "lspci -vnn | grep VGA -A 12\n",
    "```\n",
    "\n",
    "我的机器输出如下信息\n",
    "\n",
    "![](../assets/lspci_vga1.jpg)\n",
    "\n",
    "第一行输出便有硬件厂商、型号名称/序列号和 PCI ID， 大家可以看到上图中所示的 `10de:1e04`，其中冒号前半部分的 10de 表示供应商ID(这里是Nvidia)，后半部分 1e04 表示 PCI ID，用于指示图形单元模型。\n",
    "\n",
    "此外，大家还可以使用 lshw 命令来获取上述信息：\n",
    "\n",
    "```sh\n",
    "sudo lshw -numeric -class video\n",
    "```\n",
    "\n",
    "# 查询显卡具体型号\n",
    "\n",
    "最后显示设备型号为 `[10de:1e04]`，我们可以查询到该显卡的具体信息\n",
    "\n",
    "- **第一步：查询供应商**\n",
    "\n",
    "查询地址：http://pci-ids.ucw.cz/read/PC\n",
    "\n",
    "在最下方输入供应商ID（上图输出结果中第一行中冒号前的字符）\n",
    "\n",
    "![](../assets/PC_vender.jpg)\n",
    "\n",
    "这里显示出我的显卡供应商为NVIDAI\n",
    "\n",
    "![](../assets/vender_nvidia.jpg)\n",
    "\n",
    "\n",
    "- **第二步：查询显卡PCI ID**\n",
    "\n",
    "查询地址：接着在上面在查询供应商ID的结果页面\n",
    "\n",
    "(比如我的Nvidia显卡：http://pci-ids.ucw.cz/read/PC/10de ）\n",
    "\n",
    "直接<kbd>Ctrl</kbd> + <kbd>F</kbd>搜索自己的PCI ID，或者在最下方输入框里查询\n",
    "\n",
    "查询到我的显卡具体型号：[GeForce RTX 2080 Ti]\n",
    "\n",
    "![](../assets/pci_id_ie04.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 查看显卡驱动信息\n",
    "\n",
    "要查看当前 Linux 系统上所使用的显卡驱动名称，同样可以使用 lshw 命令：\n",
    "\n",
    "```sh\n",
    "sudo lshw -c video | grep configuration \n",
    "```\n",
    "\n",
    "上图中可以看到输出的显卡驱动名称有两条，其中一条为 driver=i915，我们则可以使用如下命令来检查显卡驱动的详情(另外一条操作类似)\n",
    "\n",
    "```sh\n",
    "modinfo i915\n",
    "```\n",
    "\n",
    "安装完Nvidia驱动也可通过以下命令查询驱动版本：\n",
    "```sh\n",
    "sudo dpkg --list | grep nvidia-*\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Nvidia命令行工具nvidia-smi\n",
    "\n",
    "`nvidia-smi`（The Nvidia System Management Interface）是Nvidia显卡命令行管理套件，基于NVML（Nvidia Management Library）库，旨在管理和监控Nvidia GPU设备。\n",
    "\n",
    "该套件允许管理员查询GPU设备状态，并且授权系统管理员合适的权限修改GPU设备状态，主要支持Tesla, GRID, Quadro以及TitanX的产品，有限支持其他的GPU产品\n",
    "\n",
    "nvidia-smi工具支持不同的操作系统，可以将查询信息以XML或人类可读的纯文本格式报告给标准输出或文件。关于nvidia-smi详细使用说明见: \n",
    "\n",
    "- http://developer.download.nvidia.com/compute/cuda/6_0/rel/gdk/nvidia-smi.331.38.pdf\n",
    "\n",
    "- http://developer.download.nvidia.com/compute/DCGM/docs/nvidia-smi-367.38.pdf\n",
    "\n",
    "使用nvidia-smi query:\n",
    "\n",
    "- http://nvidia.custhelp.com/app/answers/detail/a_id/3751/~/useful-nvidia-smi-queries\n",
    "\n",
    "\n",
    "**查看GPU占用动态信息**\n",
    "```sh\n",
    "watch -n 10 nvidia-smi\n",
    "```\n",
    "或者\n",
    "```sh\n",
    "nvidia-smi -l 10\n",
    "```\n",
    "\n",
    "上面命令的作用是：每10秒更新GPU信息"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. 第一列  GPU：编号0、1 \n",
    "          Fan：GPU的风扇转速，0~100%\n",
    "\n",
    "2. 第二列  Name：型号Tesla K20c、Quadro K4000\n",
    "          Temp： 温度，单位摄氏度。 \n",
    "\n",
    "3. 第三列  Perf：性能状态，P0~P12，P0表示最大性能，P12表示状态最小性能。 \n",
    "\n",
    "4. 第四列  Persistence-M：持续模式的状态，持续模式虽然耗能大，但是在新的GPU应用启动时，花费的时间更少，这里显示的是off的状态。\n",
    "          Pwr：能耗\n",
    "\n",
    "5. 第五列  Bus-Id： GPU总线，domain:bus:device.function \n",
    "\n",
    "6. 第六列  Disp.A：Display Active，表示GPU的显示是否初始化。 \n",
    "          Memory Usage 显存使用率。 \n",
    "\n",
    "7. 第七列  Volatile GPU-Util 浮动的GPU利用率。 \n",
    "\n",
    "8. 第八列   Uncorr. ECC   ECC是“Error Checking and Correcting”的简写，“错误检查和纠正”\n",
    "        Compute M是计算模式。 \n",
    "        \n",
    "显存占用和GPU占用是两个不一样的东西，显卡是由GPU和显存等组成的，显存和GPU的关系有点类似于内存和CPU的关系。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "其他常用查询命令：\n",
    "\n",
    "- [了解GPU从nvidia-smi命令开始](https://blog.csdn.net/csdnofzyk/article/details/80187919)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "参考：\n",
    "\n",
    "- https://developer.nvidia.com/nvidia-system-management-interface\n",
    "- https://blog.csdn.net/wangleiwavesharp/article/details/71642310?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.add_param_isCf&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.add_param_isCf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "165px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
